package com.boarsoft.boar.demo.tenant.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boarsoft.boar.demo.order.entity.PocOrder;
import com.boarsoft.boar.demo.order.service.PocOrderGet;
import com.boarsoft.boar.demo.tenant.entity.PocPost;

@Service("postSvc")
public class PocPostServiceImpl implements PocPostService {
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private PocPostAdd postAdd;
	@Autowired
	private PocPostGet postGet;
	@Autowired
	private PocPostDel postDel;
	@Autowired
	private PocOrderGet orderGet;

	@Override
	public boolean process(String tenantId, PocPost p) {
		PocOrder o = orderGet.get("tenant1", 4);
		log.info("Got PocOrder {}", o);
		PocPost x = postGet.get(tenantId, p.getId());
		log.info("Got PocPost {}", x);
		if (x != null) {
			log.info("Delete PocPost {}", p.getId());
			postDel.delete(tenantId, p.getId());
		}
		log.info("Add PocPost {}", p);
		return postAdd.add(tenantId, p);
	}

}